<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: zhouzixiong1
  Date: 2017/8/29
  Time: 11:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询交易记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="../../statics/css/bootstrap.min.css" rel="stylesheet">
    <link href="../../statics/css/style.css" rel="stylesheet">
    <link href="../../statics/css/ASignInNormalUser.css" rel="stylesheet">
    <link href="../../statics/css/ATopMenu.css" rel="stylesheet">
    <script src="../../statics/js/jquery-3.0.0.js"></script>
    <script src="../../statics/js/layer.js"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="title aTopMenu">查询交易记录</div>
    </div>
    <div class="row">
        <c:import url="common/ATopMenu.jsp"></c:import>
    </div>
    <div class="row">
        <div class="col-sm-6 col-sm-offset-3">
            <div class="input-group">
                <input type="text" class="form-control" name="userName" id="userName" placeholder="查询用户名，不输入为查询全部"/>
                <span class="input-group-btn">
                    <button class="btn btn-info" onclick="getAllMoney()">查询</button>
                </span>
            </div>
        </div>
        <div class="col-sm-8 col-sm-push-2">
            <table class="table table-striped" name="moneyTable" id="moneyTable" >
                <%--<caption>交易记录查询</caption>--%>
                <thead>
                <tr>
                    <td>用户名</td>
                    <td>交易金额</td>
                    <td>交易后余额</td>
                    <td>交易时间</td>
                </tr>
                </thead>
                <tbody name="moneyBody" id="moneyBody">

                </tbody>
            </table>
        </div>
    </div>
</div>

<script type="application/javascript">
    document.getElementById("MenuACheckMoney").className = "active";
//    window.open(getAllMoney());
    getAllMoney();
    function getAllMoney(){
        $("#moneyBody").empty();
        var userName = $('#userName').val();
        if(userName=="" || userName==null ){
            $.ajax({
                type:'post',
                url:'/Money/checkAllMoneyList',
                data: '',
                dataType:'json',
                success: function (data) {
                    var moneyList = data.data;
                    for(var i=0; i<moneyList.length ; i++){
                        var obj = moneyList[i];
                        var userName = obj.userName;
                        var jiaoyiMoney = obj.jiaoyiMoney > 0 ? "+" + obj.jiaoyiMoney : obj.jiaoyiMoney;
                        var totalMoeny = obj.totalMoney >= 0 ? "+" + obj.totalMoney : "-" + obj.totalMoney;
//                    var date = obj.updateDate;
                        var date = format(obj.updateDate);
                        var tr =
                            "<tr>" +
                            "<td>"+ userName +"</td>" +
                            "<td>"+ jiaoyiMoney +"</td>" +
                            "<td>"+ totalMoeny +"</td>" +
                            "<td>"+ date +"</td>" +
                            "</tr>";
                        $("#moneyBody").append(tr);
                    }
                }

            })
        }else{
            $.ajax({
                type:'post',
                url:'/Money/checkMoneyList/' + userName,
                data: '',
                dataType:'json',
                success: function (data) {
                    if(data.code=="0"){
                        var moneyList = data.data;
                        for(var i=0; i<moneyList.length ; i++){
                            var obj = moneyList[i];
                            var userName = obj.userName;
                            var jiaoyiMoney = obj.jiaoyiMoney > 0 ? "+" + obj.jiaoyiMoney : obj.jiaoyiMoney;
                            var totalMoeny = obj.totalMoney >= 0 ? "+" + obj.totalMoney : "-" + obj.totalMoney;
//                    var date = obj.updateDate;
                            var date = format(obj.updateDate);
                            var tr =
                                "<tr>" +
                                "<td>"+ userName +"</td>" +
                                "<td>"+ jiaoyiMoney +"</td>" +
                                "<td>"+ totalMoeny +"</td>" +
                                "<td>"+ date +"</td>" +
                                "</tr>";
                            $("#moneyBody").append(tr);
                        }
                    }else {
                        layer.msg(data.message);
                    }

                }

            })
        }

    }

function add0(m){return m<10?'0'+m:m }
function format(shijianchuo)
{
//shijianchuo是整数，否则要parseInt转换
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth()+1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}
</script>
</body>
</html>
